const axios = require("axios");
const moment = require("moment");
const util = require("util");
const logger = require("./logger");
const rds = require("./rds");
const tutils = require("./tutils");
const dbq = require("./dbq");
const task = require("./task");
const loyalty = require("./loyalty");
const ai = require("./ai");

//LTR-2024-08-19积分未发放的修复
async function fix0819() {
    const activity_code = "LTR-2024-08-19";
    const activity_name = "2024中国医师节抽奖活动";

    const sql = `select * from tutem_mall.eb_user_lottery_results where prize_id = 48 and uid in (select uid from tutem_mall.eb_user_bill where add_time >= 1722268800 and link_id like 'user-lottery-id-%');`;

    const [rows] = await rds.query(sql);

    let i = 0;

    for (let row of rows) {
        i += 1;
        const { id, uid, prize_id, prize_name } = row;
        const link_id = `user-lottery-${id}-prize-${prize_id}`;
        const points = 819;
        const title = `${activity_code} ${activity_name}`;
        const mark = `${activity_code} ${activity_name}`;
        console.log(
            `${i} grant uid: ${uid} link_id: ${link_id} points: ${points})`
        );
        const result = await tutils.grantPoints(
            uid,
            link_id,
            title,
            points,
            mark
        ); //因为有link_id，所以可以保证不会重复提交
        console.log("result:", result);
    }

    console.log(`done`);
}
//fix0819();
